﻿package com.designoutput.elements
{
	import com.designoutput.enum.ElementType;
	import com.designoutput.utils.Unit;
	import com.designoutput.utils.UnitUtils;

	/**
	 * 
	 * <br>
	 * StarElement -> BaseRectElement -> BaseElement ->Base
	 */	
	public class StarElement extends BaseRectElement
	{
		/**
		 * The points of the Star
		 */		
		public var starPoints:Number;
		
		/**
		 * The distance of the Star, from the outline to the inside corner
		 */		
		public var starCenterDist:Number; 


		public function StarElement()
		{
			super();
			starPoints = 5;
			starCenterDist = 0.37;
		}
		
		override public function getClassName():String{
			return ElementType.StarElement; 
		}
		
		public function setStarPoints(val:Number):void{
			this.starPoints = Math.max(3, val);
		}
		
		public function getStarPoints():Number{
			return this.starPoints;
		}
		
		public function setStarCenterDist(val:Number):void{
			var temp:Number = Math.min(Math.cos(Math.PI / getStarPoints()), val);
			temp = Math.max(0, temp);
			this.starCenterDist = temp;
		}
		
		public function getStarCenterDist():Number{
			return this.starCenterDist;
		}
		
		/**
		 * 
		 * Draw the star/poly
		 */		
		override protected function updateElement():void
		{
			super.updateElement();
			
			this.graphics.clear();
			drawPolyStar(this, 0, 0, _width, _height, starPoints, starCenterDist, [useLine, this.lineColor, this.lineAlpha, this.lineSize], [useFill, this.fillColor, this.fillAlpha]);
		}

		/**
		 * To generate the XML node, post for DB or pdf files
		 * @param xmlDoc
		 * @return 
		 */		
		override public function toXML():XML
		{
			var xmlNode:XML = super.toXML();
			
			xmlNode.@starPoints=starPoints;
			xmlNode.@starCenterDist=starCenterDist;
			
			return xmlNode;
		}

		/**
		 * Read XML node from DB or other card
		 * @param xmlNode
		 * 
		 */		
		override public function fromXML(xmlNode:XML):void
		{
			super.fromXML(xmlNode);
			starPoints=Number(xmlNode.@starPoints);
			starCenterDist=Number(xmlNode.@starCenterDist);
		}
	}
}